
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/dist/query/react";

//入库操作请求API
export const mileagecombinePropsApi = createApi({
    reducerPath: 'mileagecombineprops',
    //设置基本请求路径
    baseQuery: fetchBaseQuery({
        baseUrl: window.app
    }),
    tagTypes:['mileagecombineprops'],//定义标签
    endpoints(build) {
        return {
            //获取入库记录
            getmileagecombineprops: build.query({
                query:(para) =>({
                    url: 'DW_PropsMileageCombine/GetPropsMileageCombine',
                    method:'GET',
                    params:para,
                }),
                transformResponse(baseQuery){
                    return baseQuery;

                },
                //设置缓存时间60秒
                keepUnusedDataFor:60,
                providesTags:['mileagecombineprops']//定义标签，如果该标签失效则会触发重新访问服务器
            }),
           
            //修改一条商品入库记录
            postaddmileagecombineprops: build.mutation({
                query(data) {
                    return {
                        url: 'DW_PropsMileageCombine/AddPropsMileageCombine',
                        method: 'POST',
                        body:data
                    };
                },
                transformResponse(baseQuery){
                    return baseQuery.data;

                },
                invalidatesTags:['mileagecombineprops']//定义标签，一旦修改数据，则会使该标签失效
            }),
            //修改一条商品入库记录
            puteditmileagecombineprops: build.mutation({
                query(data) {
                    return {
                        url: 'DW_PropsMileageCombine/EditPropsMileageCombine',
                        method: 'PUT',
                        body:data
                    };
                },
                transformResponse(baseQuery){
                    return baseQuery.data;

                },
                invalidatesTags:['mileagecombineprops']//定义标签，一旦修改数据，则会使该标签失效
            }),
            postmileagecombineexcute: build.mutation({
                query:(data) =>({
                    url: 'DW_PropsMileageCombine/ExcuteDataMileageCombine',
                    method:'POST',
                    body:data,
                }),
                transformResponse(baseQuery){
                    return baseQuery.data;

                },
                
            }),
            //删除一条商品入库记录
            deletmileagecombineprops: build.mutation({
                query(key) {
                    return {
                        url: `DW_PropsMileageCombine/DelPropsMileageCombine?key=${key}`,
                        method: 'DELETE',

                    };
                },
                transformResponse(baseQuery) {
                    return baseQuery.data;

                },
                invalidatesTags: ['mileagecombineprops']//定义标签，一旦修改数据，则会使该标签失效
            }),

        }
    }
});


//导出钩子函数给外部使用，自动生成hooks的名称为`use(Endpoint_name)Query`
export const { useGetmileagecombinepropsQuery,usePostaddmileagecombinepropsMutation,usePuteditmileagecombinepropsMutation,useDeletmileagecombinepropsMutation,usePostmileagecombineexcuteMutation } = mileagecombinePropsApi;